lets_plot.facet_wrap¶
-
lets_plot.facet_wrap(facets, ncol=None, nrow=None, order=None, format=None, dir='h')¶ Splits data by one or more faceting variables. For each data subset creates a plot panel and lays out panels according to the ncol, nrow and dir settings.
- Parameters
facets (str or list) – One or more faceting variable names.
ncol (int) – Number of columns.
nrow (int) – Number of rows.
order (int or list, default=None) – Specifies ordering direction panels. 1 (or None) - ascending, -1 - descending. The order values are positionally matched to variables in facets.
format (str or list) – Specifies the format pattern for displaying faceting values. The format values are positionally matched to variables in facets.
dir ({‘h’, ‘v’}, default=’h’) – Direction: either ‘h’ for horizontal, or ‘v’, for vertical.
- Returns
Facet wrap specification.
- Return type
FeatureSpec
Note
Format patterns in the format parameter can be just a number format (like ‘d’) or a string template where number format is surrounded by curly braces: “{d} cylinders”.
For example:
‘.2f’ -> ‘12.45’,
‘Score: {.2f}’ -> ‘Score: 12.45’,
‘Score: {}’ -> ‘Score: 12.454789’.
For more info see the formatting reference.
Examples
1 2 3 4 5 6 7 8 9
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.random.normal(size=n) group = np.random.choice(['a', 'b'], size=n) ggplot({'x': x, 'group': group}, aes(x='x')) + \ geom_histogram() + facet_wrap(facets='group')
1 2 3 4 5 6 7 8 9 10 11
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 1000 np.random.seed(42) x = np.random.normal(size=n) p = [1/6, 1/3, 1/2] y = np.random.choice(p, size=n, p=p) ggplot({'x': x, 'y': y}, aes(x='x')) + \ geom_histogram() + \ facet_wrap(facets='y', order=-1, ncol=2, dir='v', format='.2f')